﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Jayden.Dll.ECMAScript
{
	public class Object
	{
		public class Property
		{
			private object m_Value;
			private Dictionary<string, object> m_Attributes = new Dictionary<string, object>();

			public Property(object value)
			{
				m_Value = value;
			}

			public object Value { get { return m_Value; } set { m_Value = value; } }
		}
		private Dictionary<string, Property> m_Properties = new Dictionary<string, Property>();

		public object this[string propertyName] { get { return Get(propertyName); } set { Set(propertyName, value); } }
		public void Set(string propertyName, object value)
		{
			Property property = null;
			if (!m_Properties.TryGetValue(propertyName, out property))
			{
				property = new Property(null);
				m_Properties.Add(propertyName, property);
			}
			property.Value = value ?? Null.Instance;
		}
		public object Get(string propertyName)
		{
			Property property = null;
			if (m_Properties.TryGetValue(propertyName, out property))
				return property.Value;
			return Undefined.Instance;
		}
		public bool Is(string propertyName) { return Get(propertyName) != Undefined.Instance; }
	}
}
